<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Contact
 *
 * @author khavu
 */
class Default_Model_Contact extends Zend_Db_Table {

    protected $_name = 'contact';
    protected $_primary = 'conid';
    protected $db;

    public function __construct() {
        $this->db = Zend_Registry::get('connectDb');
    }

    public function insert($arrParam, $opption = null) {
        if ($opption == "contact") {
            $fullname = (isset($arrParam['name'])) ? $arrParam['name'] : NULL;
            $email = (isset($arrParam['email'])) ? $arrParam['email'] : NULL;
            $content = (isset($arrParam['message'])) ? $arrParam['message'] : NULL;
            $this->db->query(" INSERT INTO `contact` (`fullname` ,`email` ,`content` ,`status` ,`date`) 
            VALUES ('$fullname', '$email', '$content', '0', NOW()); ");
        } else if ($opption == "newslettersignup") {
            $email = (isset($arrParam['email'])) ? $arrParam['email'] : NULL;
            $sql = $this->db->query(" SELECT id, status FROM newslettersignup WHERE email = '$email' LIMIT 1 ");
            $rs = $sql->fetchAll();
            if (count($rs) > 0) {
                if ($rs[0]['status'] == 0){
                    $this->db->query(" UPDATE `newslettersignup` SET status = 1 WHERE email = '$email' ");
                }
            } else {
                $this->db->query(" INSERT INTO `newslettersignup` (`email` ,`datecreated`) VALUES ('$email', NOW()); ");
            }
        }

//        $sql->execute();
    }

}